package com.easy.persondemo;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easylib.base.BaseActivity;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Pdf2Activity extends BaseActivity implements OnPageChangeListener, OnLoadCompleteListener {

    public static final String SAMPLE_FILE1 = "sample1.pdf";
    public static final String SAMPLE_FILE2 = "sample.pdf";
    @Bind(R.id.pdfView)
    PDFView pdfView;
    @Bind(R.id.tv_num)
    TextView tvNum;
    @Bind(R.id.tv_shouye)
    TextView tvShouye;
    @Bind(R.id.ll_rv)
    LinearLayout ll_rv;
    @Bind(R.id.activity_info)
    LinearLayout activityInfo;
    private int pageNumber = 0;
    private String pdfFileName;


    @Override
    public int getContentViewId() {
        return R.layout.activity_pdf1;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        displayFromAsset(SAMPLE_FILE1);
    }

    private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE1)
                .defaultPage(pageNumber)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
//                .scrollHandle(new DefaultScrollHandle(this))
                .scrollHandle(null)
                .load();
    }

    @OnClick({R.id.tv_shouye, R.id.pdfView})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_shouye:
                finish();
                break;
            case R.id.pdfView:
                if (ll_rv.getVisibility() == View.VISIBLE) {
                    ll_rv.setVisibility(View.GONE);
                } else {
                    ll_rv.setVisibility(View.VISIBLE);
                }
                break;
        }
    }

    @Override
    public void loadComplete(int nbPages) {
        tvNum.setText((String.format("%s %s / %s", "", 1, nbPages)));
    }

    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
        tvNum.setText((String.format("%s %s / %s", "", page + 1, pageCount)));
    }
}
